<template>
  <div class="app-container">
    <div class="filter-container">
      <div>
        <el-date-picker
          v-model="listQuery.checktime"
          type="daterange"
          range-separator="至"
          class="filter-item"
          style="width:300px"
          start-placeholder="指派开始日期"
          end-placeholder="指派结束日期"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>

        <el-button-group class="filter-item">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-search"
            @click="search"
          >
            搜索
          </el-button>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-refresh"
            @click="refresh"
          >
            重置
          </el-button>

        </el-button-group>
      </div>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      height="100%"
      class="table-container"
      highlight-current-row
    >

      <el-table-column
        width="80"
        label="wid"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.wid }}
        </template>
      </el-table-column>


      <el-table-column
        width="80"
        label="状态"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status==7" type="warning">已受理</el-tag>
          <el-tag v-else-if="scope.row.status==2" type="info">待处理</el-tag>
          <el-tag v-else-if="scope.row.status==3 || scope.row.status==4 || scope.row.status==5" type="success">已办理
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column
        width="430"
        label="标题"
        align="left"
      >
        <template slot-scope="scope">
          <div style="color:#409EFF;font-size:14px;cursor: pointer">
            {{ scope.row.title }}
          </div>
          <div style="display: flex;align-items: center">
            <div v-for="(item,idx) in scope.row.lingyu" class="titletag">
              {{ item }}
            </div>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        width="180"
        label="负责人"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.lid }}</div>
          <div v-if="scope.row.passon_name" class="cover">@{{ scope.row.passon_name }}</div>
        </template>
      </el-table-column>

      <el-table-column
        width="135"
        label="发帖时间"
        align="center"
        prop="create_time"
        :sortable="'custom'"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.create_time }}</div>
        </template>
      </el-table-column>
      <el-table-column
        width="135"
        label="截止时间"
        prop="endTime"
        :sortable="'custom'"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.endTime }}</div>
        </template>
      </el-table-column>
      <el-table-column
        width="180"
        label="发帖人"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.u_name }}({{ scope.row.come_from }})</div>
        </template>
      </el-table-column>

      <el-table-column
        width="135"
        label="回复时间"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.reply_time }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="更多信息"
        width="135"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            type="danger"
            icon="el-icon-more"
            size="mini"
            @click="goWid(scope.row.wid)"
          />
        </template>
      </el-table-column>
    </el-table>


    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="fetchData"
    />

  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import {getAppoint} from '@/api/user'

let id = 0
export default {
  components: {
    Pagination
  },
  data() {
    return {
      total: 0,
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() + 3600 * 1000 * 24 * 1);
            picker.$emit('pick', [end, start]);
          }
        }, {
          text: '本月',
          onClick(picker) {
            const now = new Date();
            const start = new Date(now.getFullYear(), now.getMonth(), 1)
            const end = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
            start.setTime(start.getTime());
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      list: [],
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        checktime: '',
      },
    }
  },
  created() {
    // const now = new Date();
    // const start = new Date(now.getFullYear(), now.getMonth(), 1)
    // const end = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
    // const defaultTime = [start, end]
    // this.$set(this.listQuery, 'checktime', defaultTime)
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData()
    },

    refresh() {
      this.listQuery = {
        page: 1,
        limit: 20
      }
      this.fetchData()
    },
    fetchData(column) {
      this.listLoading = true

      getAppoint(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    submit() {

    }
  }
}
</script>
